<?php
//$Id: rand_code.php 32 2009-10-02 06:17:28Z bole.chen $
error_reporting(7);
ob_clean();
//@session_name('loopoid');
@session_start();

srand((double)microtime()*1000000);
$_SESSION['rand_code'] = rand(1000,9999);
$authnum = $_SESSION['rand_code'];

$im     = imagecreate(85,30);
$bgcolor = ImageColorAllocate ($im, 0xFF, 0xFF, 0xFF);
imagefill($im,0,0,$bgcolor);

$font = "media/FacesAndCaps.ttf";
$c1 = ImageColorAllocate ($im, 0x00, 0x99, 0x33);
$c2 = ImageColorAllocate ($im, 0xFF, 0x66, 0x00);
$c3 = ImageColorAllocate ($im, 0x33, 0x66, 0xCC);

ImageTTFText($im, 16, 0, 0, 30, ${'c'.rand(1,3)}, $font, substr($authnum,0,1));
ImageTTFText($im, 16, 0, 20, 30, ${'c'.rand(1,3)}, $font, substr($authnum,1,1));
ImageTTFText($im, 16, 0, 40, 30, ${'c'.rand(1,3)}, $font, substr($authnum,2,1));
ImageTTFText($im, 16, 0, 60, 30, ${'c'.rand(1,3)}, $font, substr($authnum,3,1));

//Éú³ÉÑéÖ¤ÂëÍ¼Æ¬
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
//  HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
//  HTTP/1.0
header("Pragma: no-cache");

//  Let it more flexible!
if (function_exists("imagepng")) {
   header("Content-type: image/png");
   imagepng($im);
} elseif (function_exists("imagegif")) {
   header("Content-type: image/gif");
   imagegif($im);
} elseif (function_exists("imagejpeg")) {
   header("Content-type: image/jpeg");
   imagejpeg($im);
} else {
   die("No image support in this PHP server!");
}

ImageDestroy($im);
?>
